from django.shortcuts import render

from rest_framework.viewsets import ReadOnlyModelViewSet
# Create your views here.
from rest_framework_extensions.cache.mixins import CacheResponseMixin

from . import serializers
from .models import Area


class AreaInfoView(CacheResponseMixin,ReadOnlyModelViewSet):
    # serializer_class = serializers.AreasInfoSerializer
    # queryset = Area.objects.filter(parent=None)

    def get_serializer_class(self):
        if self.action == 'list':
            return serializers.AreasInfoSerializer
        else:
            return serializers.AreasSubsInfoSerializer

    def get_queryset(self):
        if self.action =='list':
            return Area.objects.filter(parent=None)
        else:
            return Area.objects.all()